Imports DTO
Imports System.Data.OleDb
Public Class RangBuocGiaoVienDAO
    Inherits AbstractDAO
    Public Function LayBang() As DataTable
        Dim dt As New DataTable
        Dim cn As OleDbConnection
        cn = ConnectionData()
        Dim strSQL As String
        strSQL = "select * from RangBuocGiaoVien"
        Dim da As OleDbDataAdapter
        da = New OleDbDataAdapter(strSQL, cn)
        da.Fill(dt)
        cn.Close()
        Return dt
    End Function
    Public Sub CapNhatBang(ByVal dt As DataTable)
        Dim cn As OleDbConnection
        cn = ConnectionData()
        Dim strSQL As String
        strSQL = "Select * from RangBuocGiaoVien"
        Dim da As OleDbDataAdapter
        da = New OleDbDataAdapter(strSQL, cn)
        Dim cb As New OleDbCommandBuilder(da)
        da.Update(dt)
        cn.Close()
    End Sub
    Public Function LayDanhSach() As IList
        Dim ds As New ArrayList()
        Dim cn As OleDbConnection
        cn = ConnectionData()
        Dim strSQL As String
        strSQL = "Select * from RangBuocGiaoVien"
        Dim cmd As New OleDbCommand(strSQL, cn)
        Dim dr As OleDbDataReader
        dr = cmd.ExecuteReader()
        While (dr.Read())
            Dim rbgvDTO As New RangBuocGiaoVienDTO
            rbgvDTO.MaRangBuocGiaoVien = dr("MaRangBuocGiaoVien")
            rbgvDTO.MaGiaoVien = dr("MaGiaoVien")
            rbgvDTO.Thu = dr("HoTenGiaoVien")
            rbgvDTO.TietHoc = dr("TenTat")
            rbgvDTO.TrangThai = dr("DiaChi")
            ds.Add(rbgvDTO)
        End While
        dr.Close()
        cn.Close()
        Return ds
    End Function
    Public Function TiemKiemTheoMa(ByVal marangbuocgiaovien As String) As RangBuocGiaoVienDTO
        Dim rbgvDTO As New RangBuocGiaoVienDTO
        Dim cn As OleDbConnection
        cn = ConnectionData()
        Dim strSQL As String
        strSQL = "Select * from RangBuocGiaoVien Where MaRangBuocGiaoVien = " & marangbuocgiaovien
        Dim cmd As New OleDbCommand(strSQL, cn)
        Dim dr As OleDbDataReader
        dr = cmd.ExecuteReader()
        While (dr.Read())
            rbgvDTO.MaRangBuocGiaoVien = dr("MaRangBuocGiaoVien")
            rbgvDTO.MaGiaoVien = dr("MaGiaoVien")
            rbgvDTO.Thu = dr("Thu")
            rbgvDTO.TietHoc = dr("TietHoc")
            rbgvDTO.TrangThai = dr("TrangThai")


        End While
        dr.Close()
        cn.Close()
        Return rbgvDTO
    End Function
    Public Sub Them(ByVal rbgvDTO As RangBuocGiaoVienDTO)
        Dim cn As OleDbConnection
        cn = ConnectionData()
        Dim strSQL As String
        strSQL = "Insert into RangBuocGiaoVien(MaRangBuocGiaoVien,MaGiaoVien,Thu,TietHoc,TrangThai) value= " & _
        " ( '" & rbgvDTO.MaRangBuocGiaoVien & "', '" & rbgvDTO.MaGiaoVien & "', '" & rbgvDTO.Thu & "', '" & rbgvDTO.TietHoc & "', " & _
        rbgvDTO.TrangThai & ")"
        Dim cmd As New OleDbCommand(strSQL, cn)
        cmd.ExecuteNonQuery()
        strSQL = "Select @@INDENTITY"
        cmd = New OleDbCommand(strSQL, cn)
        rbgvDTO.MaRangBuocGiaoVien = cmd.ExecuteScalar()
        cn.Close()
    End Sub
    Public Sub XoaTheoMa(ByVal marangbuocgiaovien As String)
        Dim cn As OleDbConnection
        cn = ConnectionData()
        Dim strSQL As String
        strSQL = "Delete from RangBuocGiaoVien Where MaRangBuocGiaoVien= " & marangbuocgiaovien
        Dim cmd As New OleDbCommand(strSQL, cn)
        cmd.ExecuteNonQuery()
        cn.Close()

    End Sub
    Public Sub Sua(ByVal rbgvDTO As RangBuocGiaoVienDTO)
        Dim cn As OleDbConnection
        cn = ConnectionData()
        Dim strSQL As String
        strSQL = "Update RangBuocGiaoVien Set " & _
                " MaGiaoVien= '" & rbgvDTO.MaGiaoVien & _
                "' and Thu= '" & rbgvDTO.Thu & "' and TietHoc= '" & rbgvDTO.TietHoc & _
                "' and TrangThai= " & rbgvDTO.TrangThai & "Where MaRangBuocGiaoVien= '" & rbgvDTO.MaRangBuocGiaoVien & " '"
        Dim cmd As New OleDbCommand(strSQL, cn)
        cmd.ExecuteNonQuery()
        cn.Close()
    End Sub

End Class
